package com.hmkj.core.model.user;

import com.hmkj.common.utils.ValidateUtils;
import com.hmkj.core.exception.BussinessException;
import com.hmkj.core.po.user.User;
import com.hmkj.core.po.user.UserBank;
import com.xiaoleilu.hutool.util.StrUtil;
import lombok.Data;

import java.util.function.Consumer;

@Data
public class UserBankModel extends UserBank {
    private User u;

    public UserBankModel() {
    }

    public UserBankModel(Consumer<UserBankModel> consumer) {
        consumer.accept(this);
    }

    /**
     * 添加银行卡基础校验
     */
    public static void checkBankCard(String realName, String bankCode, String bankName, String province, String city, String branch, String bankNo, String phone) {
        if (StrUtil.isBlank(realName)) {
            throw new BussinessException("真实姓名不能为空");
        }
        if (StrUtil.isBlank(bankCode)) {
            throw new BussinessException("银行卡参数有误");
        }
        if (StrUtil.isBlank(bankName)) {
            throw new BussinessException("银行名称不能为空");
        } else if (bankName.length() > 20) {
            throw new BussinessException("银行名称不能超过20个字符");
        }
//        if (StrUtil.isBlank(province)) {
//            throw new BussinessException("请选择开户省份");
//        }
//        if (StrUtil.isBlank(city)) {
//            throw new BussinessException("请选择开户城市");
//        }
//        if (StrUtil.isBlank(branch)) {
//            throw new BussinessException("开户支行不能为空");
        if (StrUtil.isNotBlank(branch) && bankCode.length() > 50) {
            throw new BussinessException("开户支行名称超过50个字符");
        }
        if (StrUtil.isBlank(phone)) {
            throw new BussinessException("预留手机号不能为空");
        } else if (!ValidateUtils.isPhone(phone)) {
            throw new BussinessException("预留手机号格式不正确");
        }

        if (StrUtil.isBlank(bankNo)) {
            throw new BussinessException("银行卡号不能为空");
        } else if (bankCode.length() > 20) {
            throw new BussinessException("银行卡号超过20个字符");
        } else if (!ValidateUtils.isNumeric(bankNo)) {
            throw new BussinessException("银行卡号格式有误");
        }

    }
}
